﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace TesterLibrary
{
    public enum QuestionType
    {
        CHOOSE_SPECIFIC_NUMBER_OF_ANSWERS,
        CHOOSE_ALL_THAT_APPLY
    };

    [Serializable]
    public class Question
    {
        protected Guid id;
        protected string text;
        protected List<Answer> answers;
        protected QuestionType type;
        protected int numberOfAnswersRequired;

        #region Properties
        public Guid ID
        {
            get { return id; }
            set { id = value; }
        }

        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        public List<Answer> Answers
        {
            get { return answers; }
            set { answers = value; }
        }

        public QuestionType Type
        {
            get { return type; }
            set { type = value; }
        }

        public int NumberOfAnswersRequired
        {
            get { return numberOfAnswersRequired; }
            set { numberOfAnswersRequired = value; }
        }
        #endregion

        /// <summary>
        /// Generate a new question with empty data and only requires one answer.
        /// </summary>
        public Question()
        {
            id = Guid.NewGuid();
            text = string.Empty;
            answers = new List<Answer>();
            type = QuestionType.CHOOSE_SPECIFIC_NUMBER_OF_ANSWERS;
            numberOfAnswersRequired = 1;
        }

        /// <summary>
        /// Print the question and answers in a well formatted manor.
        /// </summary>
        /// <returns>String containing the formatted question number, text, and answer list.</returns>
        public override string ToString()
        {
            return base.ToString();
        }

        public void ToXml(System.Xml.XmlWriter xmlWriter)
        {
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
            namespaces.Add("q", @"Schemas\Question.xsd");

            XmlSerializer serializer = new XmlSerializer(this.GetType());
            serializer.Serialize(xmlWriter, this, namespaces);
        }

        public void FromXml(System.Xml.XmlReader xmlReader)
        {
            Question newQ = new Question();
            XmlSerializer deserializer = new XmlSerializer(this.GetType());
            newQ = (Question)deserializer.Deserialize(xmlReader);

            id = newQ.id;
            text = newQ.text;
            answers = newQ.answers;
            type = newQ.type;
            numberOfAnswersRequired = newQ.numberOfAnswersRequired;
        }
    }
}

